// pages/fileprint/print/newsetting.js
var app=getApp()
Page({

  
  data: {  
    // 显示设置规格
    filemodal:true,
    // 份数
    number:1,
    // 显示余额和微信支付的弹窗
    ispay:false,
    animation:1,
    // 余额微信参数
    radio1:2,
    // 支付弹窗动画参数
    animationpay:'',
    // 打印尺寸参数
    arr5:['拉伸全图','自适应','自定义'],index5:0,
     // 对齐方式参数
     arr2:['左上','左中','左下','中上','中','中下','右上','右中','右下'],index2:4,
    //  缩放比例
     number1:100,
    //  打印范围选中参数
    type:3,
    page:2,
    value1:1,
    value2:2,
    // 配送方式选中的参数
    radio:1,
    address:'',
    // 预约打印的参数
    radio7:1,
    // 规格数据
    speclist:[],goods_id:'',last:'',near_id:'',
    // 打印尺寸
    radio5:3,
    // 横向纵向
    radio6:1,timer:''

  },

  onLoad: function (options) {
     if(options.printtype){
       this.setData({
         printtype:options.printtype
       })
     }
   console.log(options);
   
    // this.getcoupon(1)
    if(options.phototrue){
      this.setData({phototrue:options.phototrue})
    }
    if(options.photoid){
      this.setData({photoid:1})
    }
    if(options.index2){
      this.setData({index2:options.index2})
    }
    if(options.param1){
      this.setData({param1:1})
    }
    if(options.flag==17){
      this.setData({flag:17})
    }
    if(options.typearr){
        this.setData({
          typearr:1,
          flag2:1,
          param:1
        })
        this.getpages(1)
    }
    if(options.photo){
      this.setData({photo:options.photo})
    }
    if(options.param){
      this.setData({param:1})
    }
    if(options.flag2){
      this.setData({flag2:true})
    }
    if(options.flag1){
      this.setData({flag1:true})
    }
    
  
    if(options.radio5){
     
      
      this.setData({radio5:options.radio5})
      if(options.radio5==3){
        this.setData({index5:0})
      }
      if(options.radio5==4){
        this.setData({index5:1})
      }
      if(options.radio5==3){
        this.setData({index5:2})
      }
    }
    
    if(options.near_id!=='undefined'){
    this.setData({
      near_id:options.near_id,
      goods_id:options.goods_id
    })}

    
   
    
    
    if(options.name&&this.data.goods_id!=''&&options.page>1){this.getpage(options.name);
    }
    
    
   let name1=options.filename?options.filename:''
  let filepath=options.filepath?options.filepath:''
 
  
  let url=options.url?options.url:''
  if(url!=''&&url.substring(0,5)!="https"){
     url="https://zujieba.com/uploads/"+url

  }
 
  let page=options.page?options.page:1
  let sheets=options.page?options.page:1
  let name=options.name?options.name:''

  
    this.setData({filepath,url,page,name,value2:page,name1,time:options.time,sheets,basepage:page})
    
    
    if(this.data.goods_id!=''){
      
      this.getrulelist(options.param1)
    }
   
    if(options.filepath){
      this.getpages(1)
    }
   
  },


  onShow: function () {
    this.getaddress()
    // this.getrulelist()
    this.getpeisong()
    console.log(this.data.sheets);
    console.log(this.data.page);
    
  },
//   关闭显示设置规格页面的弹窗
  close(){
    this.setData({
      animation:2
    })
  setTimeout(() => {
    this.setData({
      filemodal:false
    })
  }, 1000);
  },
  // 打开显示设置规格页面的弹窗
  showsetting(){
     this.setData({
      filemodal:true,
      animation:1
     })
  },
   // 打开显示支付页面的弹窗
   showpay(){
     if(this.data.printtype){
       this.sendprintparams()
       
     }
    let paperlist= this.data.speclist.filter((item,index)=>{
      return index==this.data.i
    })
    console.log(paperlist);
     if(this.data.page==='underfined'||this.data.page==1||this.data.page==''){
       
      this.saveparam()

      return
     }
     else if(this.data.value1<1||this.data.value1>Number(this.data.page)||this.data.value2<1||this.data.value2>Number(this.data.page)||this.data.value1>this.data.value2){
       wx.showToast({
         title: '选择页数错误',
         icon:'none'
       })
      
       
    
      
       return
     }
     this.saveparam()
    

   
     
   },
    // 关闭显示支付页面的弹窗
   closepay(){
     this.setData({
      animationpay:2,
      
     })
     setTimeout(() => {
      this.setData({
       ispay:false,
        
       })
     }, 1000);
   },
  //  打印尺寸
   bindPickerChange5(e){
 
    
    this.setData({index5:e.detail.value})
    if(e.detail.value==0){
      this.setData({
         radio5:3
      })
    }
    if(e.detail.value==1){
      this.setData({
         radio5:4
      })
    }
    if(e.detail.value==2){
      this.setData({
         radio5:6
      })
    }
  },
  //  对齐方式
  bindPickerChange2(e){
 
    this.setData({
      index2:e.detail.value
    })
    
  },
  jianclick1(){
    let num=this.data.number1
    if(num==1){
      return
    }
    num--
    this.setData({number1:num})
 },
 addclick1(){
   let num=this.data.number1
   if(num==100){
     return
   }
   num++
   this.setData({number1:num})
 },
 changeinput(e){
  
  
   
    let abc=Number(e.detail.value)
    
    
    if(abc<1){

    
        this.setData({
           number1:1
        })  
        return
      }
      this.setData({
        number1:abc
     })  
},
jianclick(){
  
  
  let value=this.data.number
  
  if(value>1){
    value--
    this.setData({
      number:value
    })
    
  }
  let price=this.data. price*this.data.number*(this.data.sheets?this.data.sheets:1)
  // if(price<this.data.man){
  //    this.setData({
  //      jian:0
  //    })
  // }
  this.setData({
     priceall:price
  })
  this.getcoupon(1)
},
addclick(){
  let value=this.data.number
  value++
  this.setData({
    number:value
  })
  let price=this.data. price*this.data.number*(this.data.sheets?this.data.sheets:1)
  if(price<this.data.man){
     this.setData({
       jian:0,
       priceall,price
     })
  }
  this.setData({priceall:price})
  this.getcoupon(1)
},
toggle13(e){
  this.setData({
    type:e.currentTarget.dataset.type
  })
  let sheets
  if(this.data.page==''||this.data.page==1){sheets=1}else if(this.data.type==1){
    if(this.data.page%2==0){
      sheets=this.data.page/2
      
      
    }else{
     sheets=parseInt(this.data.page/2)+1
     
     
    }
  }else if(this.data.type==2){
       
         sheets=parseInt(this.data.page/2)
        
         
       

  }else{sheets=this.data.value2-this.data.value1+1}
  this.setData({sheets})
  let price=this.data. price*this.data.number*(this.data.sheets?this.data.sheets:1)
  if(price<this.data.man){
     this.setData({
       jian:0
     })
  }
  /*this.setData({basesheets:sheets})
  let arr=this.data.speclist[1].data
  var title
 arr.forEach((item)=>{
    if(item.checked==true){
      title=item.title
    }
 })
  
  
  

  
  if(title=="长边"||title=="短边"){
    this.setData({flag:2})
    if(sheets%2==0){
       sheets=sheets/2
    }else{
      sheets=parseInt(sheets/2)+1
    }
    this.setData({sheets})
  }else{
    this.setData({sheets,flag:1})
  }*/
  let priceall=this.data. price*this.data.number*(this.data.sheets?this.data.sheets:1)
  this.setData({
    priceall
  })
  this.getcoupon(1)
  
},
toggle(e){
       
  let radio=e.currentTarget.dataset.radio
  this.setData({
    radio
  })
  let priceall=this.data. price*this.data.number*(this.data.sheets?this.data.sheets:1)
  this.setData({priceall})
   this.getcoupon(1)
    // this.getaddress()
  
    
},
  //获取用户地址
  getaddress(){
    wx.request({
      url: 'https://zujieba.com/Api/car/address.html',
      data:{uid:wx.getStorageSync('uid')},
      method:'POST',
      success:(res)=>{
       
        if(res.data.success==1){
        let address=res.data.data.province+res.data.data.city+res.data.data.area+res.data.data.address
        this.setData({address,address_name:res.data.data.name,address_phone:res.data.data.phone,address_id:res.data.data.id})}
        else{return}
        
      }
    })
  },
  //跳转到我的地址
  navaddress(){
    wx.navigateTo({
      url: '/pages/mine/address/address',
    })
  },
  //预约打印
  toggle7(e){
    this.setData({
      radio7:e.currentTarget.dataset.radio
    })
   },
  //获取规格数据
  getrulelist(){
    
    
    wx.request({
      url: 'https://zujieba.com/Api/spec/spec',
      data:{id:this.data.goods_id},
      method:"POST",
      success:(res)=>{
      
      
      console.log(res);
      
      
      const speclist=JSON.parse(JSON.stringify(res.data.data.spec)) ||[]
      let testarr=[]
      speclist.forEach((item)=>{
          if(item.title=="颜色"){
            testarr[0]=item
          }
          if(item.title=="双面打印"){
            testarr[1]=item
          }
          if(item.title=="尺寸"){
            testarr[2]=item
          }
          if(item.title=="打印类型"){
            testarr[3]=item
          }
      })
      testarr.forEach((item,index)=>{
        
            if(index==0){
              item.data.forEach((item1)=>{
                if(this.data.param1==1||this.data.index2==0){
                  if(item.data.length==2){

                  
                  if(item1.title=="彩色"){    
                    item1.checked=true
                }}else{
                  item1.checked=true
                }
              
                }else{
                  if(item1.title=="黑白"){
                    item1.checked=true
                }
                }
               
              })
            }
            if(index==1){
              item.data.forEach((item1)=>{
                if(item1.title=="单面"){
                    item1.checked=true
                }
              })
            }
            if(index==2){
              item.data.forEach((item1)=>{
                if(item1.title=="A4"){
                    item1.checked=true
                }
              })
            }
            if(index==3){
              item.data.forEach((item1)=>{
               
                 if(this.data.flag==17){
                      if(item1.title=='证件照'){
                        item1.checked=true
                      }else{
                        if(item.data.length>=1&&item.data.length<=2&&item1.title=="普通打印"){
                          item1.checked=true
                        }
                      }
                 }else if(this.data.phototrue==1){
                    if(item1.title=='照片'){
                      item1.checked=true
                    }
                 }else{
                  if(item1.title=='普通打印'){
                  item1.checked=true
                }}


              })
            }
            this.setData({speclist:testarr})
      })

      this.getmoney()
      
    let arr=new Array()  
    speclist.forEach((item)=>{
       item.data.forEach((item1)=>{
        if(item1.checked==true){
          arr.push(item1.title)
          
          this.setData({
           specname:arr
          })
        }
       })
    })
      
      }
    })
  },
   //点击规格切换
   click(e){
    if(this.data.photo==1&&e.currentTarget.dataset.index==1){
      return
    }
    if(this.data.page==1&&e.currentTarget.dataset.index==1){
      return
    }
    if(this.data.photo!=1&&e.currentTarget.dataset.index==3){
      return
    }
    
      let speclist=this.data.speclist
     let index=  this.data.speclist[e.currentTarget.dataset.index].data.findIndex(item=>{
         return item.checked
       })
        speclist[e.currentTarget.dataset.index].data[index].checked=false
       speclist[e.currentTarget.dataset.index].data[e.currentTarget.dataset.i].checked=true
       this.setData({
           speclist,
           i:e.currentTarget.dataset.i
       })
       
    
    
    
    if(e.currentTarget.dataset.index==0){
      this.setData({
         a:e.currentTarget.dataset.id
      })
      
   }else{
     if(e.currentTarget.dataset.index==1){
       this.setData({
         b:e.currentTarget.dataset.id
       })
     }else{this.setData({
       c:e.currentTarget.dataset.id
     })}
   }   
  this.getmoney()
  let arr=new Array()  
  speclist.forEach((item)=>{
     item.data.forEach((item1)=>{
      if(item1.checked==true){
        arr.push(item1.title)
      
        this.setData({
         specname:arr
        })
      }
     })
  })
    
  
  
  },
     //获取规格价钱
     getmoney(){
      let arr9=[]
      this.data.speclist.forEach((item,index)=>{
         item.data.forEach((item1)=>{
           if(item1.checked==true)
           {arr9.push(item1.id)}
            
         })
      })
   let str=arr9.join('_')
      
      this.setData({spec_id:str})
      const spec_id=str
      const  number=this.data.number
      const goods_id=this.data.goods_id
      const params={spec_id,goods_id,number}
        wx.request({
          url: 'https://zujieba.com/Api/spec/spec_price.html',
          data:params,
          method:'POST',
          success:(res)=>{
           console.log(params);
           
            console.log(res);
            
            let price=res.data.data
          
            this.setData({
              price
            })
            let priceall=this.data. price*this.data.number*(this.data.sheets?this.data.sheets:1)
            this.setData({priceall})
            this.getcoupon(1)
          }
        })
        
    },
    payclick1(){
      this.setData({
        onshow:false
      })
    
     
     this.throttle(()=>{

      let jpautoalign
      if(this.data.index2==0){
         jpautoalign='z1'
      }else if(this.data.index2==1){
       jpautoalign='z4'
      }else if(this.data.index2==2){
       jpautoalign='z7'
      }else if(this.data.index2==3){
       jpautoalign='z2'
      }else if(this.data.index2==4){
       jpautoalign='z5'
      }else if(this.data.index2==5){
       jpautoalign='z8'
      }else if(this.data.index2==6){
       jpautoalign='z3'
      }else if(this.data.index2==7){
       jpautoalign='z6'
      }else if(this.data.index2==8){
       jpautoalign='z9'
      }
     
   /*  let jpautoscale
        if(this.data.radio5==2){
           jpautoscale=this.data.suofang+'%'
         
        }else{
          jpautoscale=this.data.radio5
        }
        */
        
        let sheets
        
        if(this.data.page==''||this.data.page==1){sheets=1}else if(this.data.type==1){
          if(this.data.page%2==0){
            sheets=this.data.page/2
           
            
          }else{
           sheets=Number(this.data.page/2)+1
           
           
          }
        }else if(this.data.type==2){
             
               sheets=Number(this.data.page/2)
               
               
             
 
        }else{sheets=this.data.value2-this.data.value1+1}
       
        let radio5=this.data.radio5
       
        
        let num = this.data.number1
        if(this.data.radio5==6){
          if(this.data.number1>100){
             radio5='100%'
          }else if(this.data.number1=0||this.data.number1==''){
             radio5="100%"
          }
          else{
            
             radio5=num+'%'
          }
          
           
        }
        this.setData({
          number1:num
        })
       
        var jppagerange
       var   jptype
       if(this.data.name&&this.data.page>1){
         jppagerange=this.data.value1+'_'+this.data.value2
         jptype =this.data.type
       }else{
         jppagerange=''
         jptype =''
       }
         
       let priceid=''
       if(this.data.radio1==3){
          priceid=this.data.taocan[this.data.taocanindex].id
       }
      
       
       const spec_id=this.data.spec_id
       const uid=wx.getStorageSync('uid')
       const goods_id=this.data.goods_id
       const file=this.data.url
       const store_id=this.data.near_id
       const pay=this.data.radio1 
       const dmcopies=this.data.number
       const deli=this.data.radio
       const coupon_id=this.data.coupon_id
        const address_id=this.data.address_id
       const params={uid,goods_id,spec_id,coupon_id,jppagerange,pay,jptype,dmcopies,deli,file,sheets,address_id,jpautoalign,dmorientation:this.data.radio6,jpautoscale:radio5,page:this.data.page,now:this.data.radio7,priceid}
      
       
       var that =this
       wx.request({
         url: 'https://zujieba.com/Api/order/new_add_order.html',
         data:params,
         method:'POST',
         success:(res)=>{
         
           if(res.data.success==1){
           that.setData({
             code:res.data.data
           })
           
           
           let price=that.data. price*that.data.number*(that.data.sheets?that.data.sheets:1)-(that.data.jian?that.data.jian:0)
           
           
            wx.navigateTo({
              url: '/pages/fileprint/print/newsetting?payall='+price+'&code='+res.data.data,
            })
          
          
           
         }else{
           wx.showToast({
             title: res.data.tips,
             icon:'none',
             mask:true
           })
         }
        
        }
        
    
       })
     },1500)


   },
    //节流
    throttle:function(func,wait){
     
      var timer=this.data.timer
      clearTimeout(timer)
     timer= setTimeout(()=>{
        func()
        
        
        
      },3000)
      this.setData({timer})
        
         
      
       
    },
    saveparam(){
      app.globalData.specname=this.data.specname
      app.globalData.page=this.data.page
      app.globalData.number=this.data.number
      app.globalData.sheets=this.data.sheets
      
      
      let jpautoalign
      if(this.data.index2==0){
         jpautoalign='z1'
      }else if(this.data.index2==1){
       jpautoalign='z4'
      }else if(this.data.index2==2){
       jpautoalign='z7'
      }else if(this.data.index2==3){
       jpautoalign='z2'
      }else if(this.data.index2==4){
       jpautoalign='z5'
      }else if(this.data.index2==5){
       jpautoalign='z8'
      }else if(this.data.index2==6){
       jpautoalign='z3'
      }else if(this.data.index2==7){
       jpautoalign='z6'
      }else if(this.data.index2==8){
       jpautoalign='z9'
      }
     
   /*  let jpautoscale
        if(this.data.radio5==2){
           jpautoscale=this.data.suofang+'%'
         
        }else{
          jpautoscale=this.data.radio5
        }
        */
        
        let sheets
        
        if(this.data.page==''||this.data.page==1){sheets=1}else if(this.data.type==1){
          if(this.data.page%2==0){
            sheets=this.data.page/2
           
            
          }else{
           sheets=parseInt(this.data.page/2)+1
           
           
          }
        }else if(this.data.type==2){
             
               sheets=parseInt(this.data.page/2)
               
               
             
 
        }else{sheets=this.data.value2-this.data.value1+1}
       
        let radio5=this.data.radio5
       
        
        let num = this.data.number1
        if(this.data.radio5==6){
          if(this.data.number1>100){
             radio5='100%'
          }else if(this.data.number1=0||this.data.number1==''){
             radio5="100%"
          }
          else{
            
             radio5=num+'%'
          }
          
           
        }
        this.setData({
          number1:num
        })
        
        var jppagerange
       var   jptype
       if(this.data.name&&this.data.page>1){
         jppagerange=this.data.value1+'_'+this.data.value2
         jptype =this.data.type
       }else{
         jppagerange=''
         jptype =''
       }
         
       let priceid=''
       if(this.data.radio1==3){
          priceid=this.data.taocan[this.data.taocanindex].id
       }
       const spec_id=this.data.spec_id
       const uid=wx.getStorageSync('uid')
       const goods_id=this.data.goods_id
       const file=this.data.url
       const store_id=this.data.near_id
       
       const dmcopies=this.data.number
       const deli=this.data.radio
       const coupon_id=this.data.coupon_id
        const address_id=this.data.address_id
       const params={uid,goods_id,spec_id,coupon_id,jppagerange,jptype,dmcopies,deli,file,sheets,address_id,jpautoalign,dmorientation:this.data.radio6,jpautoscale:radio5,page:this.data.page,now:this.data.radio7,priceid}
      
       var that=this
      wx.request({
        url: 'https://zujieba.com/Api/car/add_car.html',
        data:{uid,goods_id,spec_id,coupon_id,jppagerange,jptype,dmcopies,deli,file,sheets,address_id,jpautoalign,dmorientation:this.data.radio6,jpautoscale:radio5,page:this.data.page,now:this.data.radio7,priceid},
        method:'POST',
        success:(res)=>{
          console.log(res);
          
           
           
           let price=that.data. price*that.data.number*(that.data.sheets?that.data.sheets:1)-(that.data.jian?that.data.jian:0)+(that.data.radio==2?that.data.typeobj.dema:0)
           
           let name1=this.data.name1
           if(!this.data.name1){
               name1=this.data.name
           }
            wx.navigateTo({
              url: '/pages/fileprint/print/newsetting?payall='+price+'&id='+res.data.data+'&filename='+name1,
            })
        },
        fail:(res)=>{
          console.log(res);
          
        }
      })
    },
     //预览
  preview(){
    wx.showLoading({
      title: '正在打开',
      
    })
   this.throttle(()=>{
    this.setData({
      onshow:false
    })
    
    
   

    if(this.data.goods_id!=''){
      this.setData({show3:1})
    }

    if(!this.data.filepath&&this.data.goods_id){
      wx.showLoading({
        title: '正在打开',
      })
      this.throttle(()=>{this.getimg(1,1)},1500)
      
    }
    else if(this.data.param==1&&!this.data.goods_id){
      
      
      wx.downloadFile({
        url: this.data.url,
        success:(res)=>{
          
          let file=res.tempFilePath
          wx.openDocument({
            filePath: file,
            
          })
        }
      })
    }else if(!this.data.filepath&&!this.data.goods_id&&this.data.flag2!=1){
      
     
      wx.previewImage({
        current: this.data.url,
        urls: [this.data.url]
      })
    } else if(this.data.typearr==1&&!this.data.goods_id){
      
      
      wx.previewImage({
        urls: app.globalData.arr,
      })
    }else{
      
      
      let url=this.data.url
      wx.downloadFile({
        url: url,
        success:(res)=>{
          wx.openDocument({
            filePath: res.tempFilePath,
          })
        }
      })
    }
    
    
     
 
   },3000)
  
    
  },
  //图片预览的接口
  getimg(status,type){
    let jppagerange=this.data.value1+"_"+this.data.value2
    let jpautoscale=this.data.radio5
    if(this.data.radio5==3){
      jpautoscale=3
    }else if(this.data.radio5==4){
      jpautoscale=4
    }else if(this.data.radio5==6){
      jpautoscale=this.data.number1+"%"
    }
    let jpautoalign
    if(this.data.index2==0){
       jpautoalign='z1'
    }else if(this.data.index2==1){
     jpautoalign='z4'
    }else if(this.data.index2==2){
     jpautoalign='z7'
    }else if(this.data.index2==3){
     jpautoalign='z2'
    }else if(this.data.index2==4){
     jpautoalign='z5'
    }else if(this.data.index2==5){
     jpautoalign='z8'
    }else if(this.data.index2==6){
     jpautoalign='z3'
    }else if(this.data.index2==7){
     jpautoalign='z6'
    }else if(this.data.index2==8){
     jpautoalign='z9'
    }
      wx.request({
        url: 'https://zujieba.com/Api/test2/show.html',
        method:"POST",
        data:{goodsid:this.data.goods_id,spec_id:this.data.spec_id,dmorientation:this.data.radio6,dmcopies:this.data.number,jpautoscale,jpautoalign,file:this.data.url,status,type,jppagerange,jptype:this.data.type},
        success:(res)=>{
          
          if(res.data.success==1){
            this.getimg1(1,2)
          }else{
            wx.hideLoading()
            wx.showToast({
              title: res.data.data.msg,
              icon:'none',
              mask:true
            })
          }
          
        }
      })
  },
  getimg1(status,type){
    
    let jppagerange=this.data.value1+"_"+this.data.value2
    let jpautoscale=this.data.radio5
    if(this.data.radio5==3){
      jpautoscale=3
    }else if(this.data.radio5==4){
      jpautoscale=4
    }else if(this.data.radio5==6){
      jpautoscale=this.data.number1+"%"
    }
    let jpautoalign
    if(this.data.index2==0){
       jpautoalign='z1'
    }else if(this.data.index2==1){
     jpautoalign='z4'
    }else if(this.data.index2==2){
     jpautoalign='z7'
    }else if(this.data.index2==3){
     jpautoalign='z2'
    }else if(this.data.index2==4){
     jpautoalign='z5'
    }else if(this.data.index2==5){
     jpautoalign='z8'
    }else if(this.data.index2==6){
     jpautoalign='z3'
    }else if(this.data.index2==7){
     jpautoalign='z6'
    }else if(this.data.index2==8){
     jpautoalign='z9'
    }
      wx.request({
        url: 'https://zujieba.com/Api/test2/show.html',
        method:"POST",
        data:{goodsid:this.data.goods_id,spec_id:this.data.spec_id,dmorientation:this.data.radio6,dmcopies:this.data.number,jpautoscale,jpautoalign,file:this.data.url,status,type,jppagerange,jptype:this.data.type},
        success:(res)=>{
        
          if(res.data.success==1){
              this.getimg2(1,3,res.data.data.data.task_id)
              
          }else{
            wx.hideLoading()
            wx.showToast({
              title: res.data.tips,
              mask:true
            })
          }
          
        }
      })
  },
 
  getimg2(status,type,task_id){
  
    
    let jppagerange=this.data.value1+"_"+this.data.value2
    let jpautoscale=this.data.radio5
    if(this.data.radio5==3){
      jpautoscale=3
    }else if(this.data.radio5==4){
      jpautoscale=4
    }else if(this.data.radio5==6){
      jpautoscale=this.data.number1+"%"
    }
    let jpautoalign
    if(this.data.index2==0){
       jpautoalign='z1'
    }else if(this.data.index2==1){
     jpautoalign='z4'
    }else if(this.data.index2==2){
     jpautoalign='z7'
    }else if(this.data.index2==3){
     jpautoalign='z2'
    }else if(this.data.index2==4){
     jpautoalign='z5'
    }else if(this.data.index2==5){
     jpautoalign='z8'
    }else if(this.data.index2==6){
     jpautoalign='z3'
    }else if(this.data.index2==7){
     jpautoalign='z6'
    }else if(this.data.index2==8){
     jpautoalign='z9'
    }
    let params={goodsid:this.data.goods_id,spec_id:this.data.spec_id,dmorientation:this.data.radio6,dmcopies:this.data.number,jpautoscale,jpautoalign,file:this.data.url,status,type,jppagerange,task_id,jptype:this.data.type}
   
    
      wx.request({
        url: 'https://zujieba.com/Api/test2/show.html',
        method:"POST",
        data:{goodsid:this.data.goods_id,spec_id:this.data.spec_id,dmorientation:this.data.radio6,dmcopies:this.data.number,jpautoscale,jpautoalign,file:this.data.url,status,type,jppagerange,task_id,jptype:this.data.type},
        success:(res)=>{
         
          if(res.data.success==1){
              wx.hideLoading()
              if(res.data.data.data.task_result.code!=200){
                wx.showToast({
                  title: res.data.data.data.task_result.msg,
                  icon:'none',
                  mask:true
                })
                return
              }
              let url=res.data.data.data.task_result.data.img_list[0]
            
            
                wx.previewImage({
                  urls: res.data.data.data.task_result.data.img_list,
                })
              
            
           
              
              
              
              
             
             
          }else{
            wx.hideLoading()
            wx.showToast({
              title: res.data.tips,
              mask:true
            })
          }
          
        }
      })
  },
  toggle6(e){
    this.setData({
      radio6:e.currentTarget.dataset.radio
    })
    this.getpages(e.currentTarget.dataset.radio)
 },
 getpages(direction){
  wx.showLoading({
    title: '获取页数',
    mask:true
  })
 let goods_id
 if(this.data.goods_id){
      goods_id=this.data.goods_id
 }else{
    goods_id=''
 }


  wx.request({
    url: 'https://zujieba.com/Api/test2/printing.html',
    data:{goods_id:goods_id,file:this.data.name,dmOrientation:direction},
    success:(res2)=>{
      wx.hideLoading()
       if(res2.data.success==1){
         this.setData({
           page:res2.data.data.data.pages,
           value2:res2.data.data.data.pages,
          
         })
         this.toggle14()
       }
      
      else{
        //  wx.showToast({
        //    title: res2.data.data.msg,
        //  })
      }
      
      
      /*let imgurl=res2.data.data.data.task_result.data.img_list
      let page=imgurl.length
      app.globalData.arr=imgurl*/
     
     
    },
    fail:(res)=>{
     
      wx.hideLoading()
    }
    

  })
},
toggle14(){
      
  let sheets
  if(this.data.page==''||this.data.page==1){sheets=1}else if(this.data.type==1){
    if(this.data.page%2==0){
      sheets=this.data.page/2
      
      
    }else{
     sheets=parseInt(this.data.page/2)+1
    
     
    }
  }else if(this.data.type==2){
       
         sheets=parseInt(this.data.page/2)
        
         
       

  }else{sheets=this.data.value2-this.data.value1+1}
  this.setData({sheets})
  let price=this.data. price*this.data.number*(this.data.sheets?this.data.sheets:1)+(this.data.radio==2?this.data.typeobj.dema:0)
  if(price<this.data.man){
     this.setData({
       jian:0
     })
  }
  
  
  
},
  //用户选的页数
  getpage(name){
   
    let num=this.data.value1+"_"+this.data.value2
   

   
    wx.request({
      url:'https://zujieba.com/Api/upload/save_file.html',
      data:{filename:name,num,type:this.data.type},
      method:'POST',
      success:(res)=>{
      
      let url= res.data.data.slice(23)
      url="https://zujieba.com"+url
     
      this.setData({url})
      
      }
    })
  },
  getcoupon(type){
    const uid=wx.getStorageSync('uid')
    
     
     
     let price=this.data. priceall
 
     
   wx.request({
     url: 'https://zujieba.com/Api/coupon/store_coupon.html',
     data:{type:type,uid,store_id:this.data.near_id,price},
     method:"POST",
     success:(res)=>{
      console.log(res);
      
       
       let coupon=[]
       let nocoupon=res.data.data.coupon || 0
       let numberobj=res.data.data.number
       this.setData({nocoupon,numberobj})
       nocoupon.forEach((item)=>{
         if(this.data.priceall>=item.man){
          coupon.push(item)
         }
       })
     
       var max
       for( var i=0;i<coupon.length;i++){
           for(var j=i;j<coupon.length;j++){
               if(coupon[i].jian<coupon[j].jian){
                 max=coupon[j].jian
                 
                 coupon[j].jian=coupon[i].jian
                 coupon[i].jian=max
               }
           }
       }
     
       if(coupon.length==0){
        this.setData({
          jian:0,
          coupon_id:''
       })
       return
       }
       this.setData({
          jian:coupon[0].jian,
          coupon_id:coupon[0].id
       })
       
       
       
       
     }

   })
},
change1(e){
 
  this.setData({
    value1:Number(e.detail.value)
  })
let sheets=this.data.value2-e.detail.value+1
this.setData({
  sheets
})

let price=this.data. price*this.data.number*(this.data.sheets?this.data.sheets:1)
if(price<this.data.man){
   this.setData({
     jian:0
   })
}
let priceall=this.data. price*this.data.number*(this.data.sheets?this.data.sheets:1)
   this.setData({priceall})
   this.getcoupon(1)

 
},
change2(e){
 
 this.setData({
   value2:Number(e.detail.value)
 })
 let sheets=e.detail.value-this.data.value1+1
 this.setData({
   sheets
 })
 let price=this.data. price*this.data.number*(this.data.sheets?this.data.sheets:1)
 if(price<this.data.man){
    this.setData({
      jian:0
    })
 }
 let priceall=this.data. price*this.data.number*(this.data.sheets?this.data.sheets:1)
   this.setData({priceall})
   this.getcoupon(1)
},
  //获取配送方式
  getpeisong(){
   
    
    wx.request({
      url: 'https://zujieba.com/Api/store/type.html',
      data:{pid:this.data.near_id},
      success:(res)=>{
       
        
       
        //tp dema package
       let typeobj= res.data.data
       this.setData({
           typeobj
       })
      //  this.getyuemoney()
      
  }
})
  },
  /**
   * 尺寸调整接口
   * 
   */
  sendprintparams(){
    console.log(this.data.speclist);
    
  let arr= this.data.speclist[2].data.filter((item)=>{
     return item.checked
   })
   console.log(arr);
   

    wx.request({
      url: 'https://zujieba.com/Api/upload/photo_save',
      data:{type:this.data.printtype,status:arr[0].title,pic:this.data.url},
      method:"POST",
      success:(res)=>{
       console.log(res);
       this.data.url=res.data
     
  }})}
})